home *** CD-ROM | disk | FTP | other *** search
- Path: cs.tu-berlin.de!news
- From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
- Newsgroups: comp.lang.c++
- Subject: Re: Inheritance and function signatures
- Date: Mon, 11 Mar 1996 19:47:30 +0100
- Organization: Technical University of Berlin
- Message-ID: <31447542.6E69@cs.tu-berlin.de>
- References: <MANOWAR.96Mar11132010@dilo.engin.umich.edu>
- NNTP-Posting-Host: 130.149.17.231
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- Krisztian Flautner wrote:
- >
- > Take the following example:
- >
- > #include <iostream.h>
- >
- > class A {
- > public:
- > virtual void print();
- > virtual void print(int a, int b) = 0;
- > };
- >
- > class B : public A {
- > public:
- > void print(int a, int b);
- > };
- >
- > void A::print()
- > {
- > cout << "A::print()" << endl;
- > }
- >
- > void B::print(int a, int b)
- > {
- > cout << "B::print(int " << a << ", int " << b << ")" << endl;
- > }
- >
- > main()
- > {
- > B* bb;
- >
- > bb = new B();
- >
- > bb->print();
- > }
- >
- > I was surprised to see that the call to bb->print() causes an error using
- > several compilers. G++ produces the following error message:
- >
- > t.cc: In function `int main()':
- > t.cc:34: too few arguments for method `void B::print(int, int)'
- >
- > It seems that function signitures are not properly inherited. Is this
- > a bug or a feature ?
- >
-
- A function defined in a derived class hides all inherited functions with the
- same name. It is defined this way in the April draft as well as in the
- original language. Use a qualifier to correct this problem: bb->A::print() (
- and thank God it's not a virtual function ). A rather annoying rule, isn't
- it?
-
- Bye
-
- Roman
-